import { createRouter, createWebHistory } from "vue-router";

//导入组件
import LoginVue from "../views/Login.vue";
import LayoutVue from "../views/LayOut.vue"; // 修正为正确的文件名
import AdminVue from "../views/admin/index.vue";
import BreedingEntVue from "../views/breedingEnt/index.vue";
import FarmingEntVue from "../views/farmingEnt/index.vue";
import MarketEntVue from "../views/marketEnt/index.vue";
import SlaghteringEntVue from "../views/slaghteringEnt/index.vue";
import CreateSlauBatchVue from "../views/slaghteringEnt/CreateSlauBatch.vue";
import BatchListVue from "../views/slaghteringEnt/BatchList.vue";
import WholesalerRequestVue from "../views/slaghteringEnt/WholesalerRequest.vue";

// 使用懒加载导入批发商相关组件，解决循环依赖问题
const WholBatchCreateVue = () => import("../views/farmingEnt/WholBatchCreate.vue");
const WholBatchDetailVue = () => import("../views/farmingEnt/WholBatchDetail.vue");

//定义路由关系
const routes = [
    {
        path: "/login",
        component: LoginVue,
    },
    {
        path: "/admin",
        component: AdminVue,
    },
  
    {
        path: "/",
        component: LayoutVue,
        // 登录后从定向到分类管理的页面，默认显示分类管理页面
        redirect: "/ent/breeding",
        children: [
            {
                path: "/ent/breeding",
                component: BreedingEntVue,
            },
            {
                path: "/ent/farm",
                component: FarmingEntVue,
            },
            {
                path: "/ent/market",
                component: MarketEntVue,
            },
        
            {
                path: "/ent/slaghter",
                component: SlaghteringEntVue,
            },
            
            // 批发商相关路由
            {
                path: "/wholesaler/batch/create", 
                component: WholBatchCreateVue
            },
            {
                path: "/wholesaler/batch/detail/:id",
                component: WholBatchDetailVue,
                props: true
            },
            {
                path: "/wholesaler/batch/update/:id",
                component: WholBatchCreateVue,
                props: true
            },
        ],
    },
    
    // 屠宰企业相关路由
    {
        path: "/ent/slaghter/create",
        component: CreateSlauBatchVue,
    },
    {
        path: "/ent/slaghter/batch-list",
        component: BatchListVue,
    },
    {
        path: "/ent/slaghter/wholesaler-request",
        component: WholesalerRequestVue,
    },
];

//创建路由器
const router = createRouter({
    history: createWebHistory(),
    routes: routes,
});

//导出路由
export default router;